<?php
class Tools
{
  const GENERAL_LIMIT = 10;

  static public $letters = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'w', 'y', 'z');

  static public function slugify($text)
  {
    // replace all non letters or digits by -
    $text = preg_replace('/\W+/', '-', $text);

    // trim and lowercase
    $text = strtolower(trim($text, '-'));

    return $text;
  }

  static public function trimText($text, $trim_length = 200)
  {
    $length = strlen($text);
    $more = false;

    $trimmed_text = substr($text, 0, $trim_length);
    if ($length > $trim_length)
    {
      $trimmed_text .= "...";
      $more = true;
    }

    return array('value' => $trimmed_text, 'more' => $more);
  }

  static public function getKeywords($collection = array(), $begin = '')
  {
    $keywords = $begin;
    foreach ($collection as $item)
      $keywords .= $item->getName().',';
    $keywords = substr_replace($keywords ,"",-1);
    return $keywords;
  }
}
